﻿using AIVision.Model.EntityModels;
using AIVision.Repository.Services;
using AIVision.UI.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AIVision.UI.Views
{
    /// <summary>
    /// SetCameraView.xaml 的交互逻辑
    /// </summary>
    public partial class SetCameraView : UserControl
    {
        private readonly CameraService cameraService;
        private SetCameraViewModel dataModel;
        public SetCameraView(CameraService cameraService)
        {
            InitializeComponent();
            dataModel = this.DataContext as SetCameraViewModel;
            this.cameraService = cameraService;
            LoadData();
        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {
            var camera = gridCamera.SelectedItem as CameraDto;
            cameraService.DeleteCamera(camera);
            LoadData();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            cameraService.SaveCameras(dataModel.CameraList.ToList());
            LoadData();
        }

        private void LoadData()
        {
            dataModel.CameraList.Clear();
            foreach (var item in cameraService.GetAllCameras())
            {
                dataModel.CameraList.Add(item);
            }
        }
    }
}
